package 二叉树;

public class LC_701二叉搜索树中的插入操作 {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public TreeNode insertIntoBST(TreeNode root, int val) {
        if(root==null){
            TreeNode node=new TreeNode(val);
            return node;
        }
        if(val<root.val)
            root.left=insertIntoBST(root.left,val);
        if(val>root.val)
            root.right=insertIntoBST(root.right,val);
        return root;
    }
}
